# fix_torch.py
import os
import sys
from utils.logger import logger

def fix_torch_dll_path():
    """修复Windows下PyTorch DLL加载路径问题"""
    if sys.platform == 'win32':
        try:
            import torch
            torch_dir = os.path.dirname(torch.__file__)
            dll_dir = os.path.join(torch_dir, 'lib')
            
            if os.path.exists(dll_dir):
                # 添加PyTorch DLL目录到系统PATH
                os.environ['PATH'] = dll_dir + os.pathsep + os.environ.get('PATH', '')
                return True
        except Exception as e:
            logger.info(f"修复PyTorch路径失败: {e}")
    return False